<?php

namespace app\common\logic;

use app\common\model\Archives;

class ArchivesLogic
{
    // 提现规则
    public static function getCashRule()
    {
        return Archives::find(4);
    }

    public static function saveCashRule($data)
    {
        $arc = Archives::where('id',4)->save($data);
    }

    public static function getArticleList($data)
    {
        $where = [];
        if (!empty($data['category_id'])) {
            $where[] = ['category_id','=',$data['category_id']];
        }
        $list = Archives::where($where)
            ->order('id desc')
            ->paginate(['list_rows'=>15,'page'=>$data['page']]);
        return $list;
    }

    // 关于我们
    public static function getAbout()
    {
        return Archives::find(3);
    }

    // 邀请规则
    public static function getApplyRule()
    {
        return Archives::find(5);
    }

    public static function saveApplyRule($data)
    {
        return Archives::where('id',5)->save($data);
    }


    // 用户协议
    public static function getAgreement()
    {
        return Archives::find(6);
    }

    // 隐私政策
    public static function getPolicy()
    {
        return Archives::find(7);
    }

    public static function getArchives($type)
    {
        switch ($type) {
            case 'about':  //关于
                $data = self::getAbout();
                break;
            case 'apply': // 邀请
                $data = self::getApplyRule();
                break;
            case 'cash':// 提现
                $data = self::getCashRule();
                break;
            case 'agree':// 协议
                $data = self::getAgreement();
                break;
            case 'policy':// 政策
                $data = self::getPolicy();
                break;
            default:
                $data = self::getAbout();
        }
        return $data;
    }
}